home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / FlyThrough 1.1.2 / src / Source / QD3D General Tools / C3Lights.cp < prev    next >
Encoding:
Text File  |  1995-12-01  |  2.3 KB  |  100 lines  |  [TEXT/CWIE]

  1. //
  2. //    C3Lights.cp
  3. //
  4. //    class C3Lights
  5. //    Class for constructing a group consisting of 3 lights.
  6. //
  7. //    Based on the "Start Here" sample code from Apple.
  8. //
  9. //    by James Jennings
  10. //    Started November 22, 1995
  11. //
  12.  
  13. #include "C3Lights.h"
  14.  
  15. #include <QD3DMath.h>
  16. #include <QD3DShader.h>        // defines Q3ColorRGB_Set()
  17. #include <QD3DGroup.h>        // defines Q3LightGroup_New()
  18.  
  19. //
  20. //    class CAmbient
  21. //        constructs an ambient light
  22. //
  23. void
  24. C3Lights::CAmbient::Make()
  25. {    // construct an ambient light
  26.     TQ3LightData    data;
  27.     
  28.     // generic light stuff: There is no location or direction.
  29.     data.isOn = kQ3True;
  30.     ::Q3ColorRGB_Set(&(data.color), 1.0, 1.0, 1.0); // White Light
  31.     data.brightness = .2;
  32.     mObject = ::Q3AmbientLight_New(&data);
  33.     ThrowIfNil_(mObject);
  34. }
  35.  
  36. //
  37. //    class CPoint
  38. //        constructs a point light source
  39. //
  40. void
  41. C3Lights::CPoint::Make()
  42. {    // construct a point light source
  43.     TQ3PointLightData    data;
  44.     
  45.     // generic light stuff
  46.     data.lightData.isOn = kQ3True;
  47.     ::Q3ColorRGB_Set(&(data.lightData.color), 1.0, 1.0, 1.0); // White Light
  48.     data.lightData.brightness = 1.0;
  49.     // point light specific stuff: It has a location, but no direction
  50.     data.castsShadows = kQ3False;
  51.     data.attenuation = kQ3AttenuationTypeNone;
  52.     ::Q3Point3D_Set( &(data.location), 10.0, 10.0, 10.0);
  53.     mObject = ::Q3PointLight_New(&data);
  54.     ThrowIfNil_(mObject);
  55. }
  56.  
  57. //
  58. //    class CFill
  59. //        constructs a fill light source
  60. //
  61. void
  62. C3Lights::CFill::Make()
  63. {    // construct a fill light
  64.     TQ3DirectionalLightData    data;
  65.     
  66.     // generic light stuff
  67.     data.lightData.isOn = kQ3True;
  68.     ::Q3ColorRGB_Set(&(data.lightData.color), 1.0, 1.0, 1.0); // White Light
  69.     data.lightData.brightness = 0.2;
  70.     // fill light specific stuff: it has direction, but no location
  71.     data.castsShadows = kQ3False;
  72.     ::Q3Vector3D_Set( &(data.direction), 10.0, 10.0, 10.0 );
  73.     mObject = ::Q3DirectionalLight_New(&data);
  74.     ThrowIfNil_(mObject);
  75. }
  76.  
  77. //
  78. //    class C3Lights
  79. //        constructs a light group with three lights in it
  80. //
  81. void
  82. C3Lights::Make()
  83. {    // make the group
  84.     mObject = ::Q3LightGroup_New();
  85.     ThrowIfNil_(mObject);
  86.     // construct the three lights
  87.     CAmbient    ambient;
  88.     CPoint        point;
  89.     CFill        fill;
  90.     // add the lights to the group
  91.     TQ3GroupPosition pos;
  92.     pos = ::Q3Group_AddObject(mObject, ambient.Get());
  93.     ThrowIf_(pos==0);
  94.     pos = ::Q3Group_AddObject(mObject, point.Get());
  95.     ThrowIf_(pos==0);
  96.     pos = ::Q3Group_AddObject(mObject, fill.Get());
  97.     ThrowIf_(pos==0);
  98. }
  99.  
  100.